<?php

function exportexcel($data = array(), $title = array(), $filename = 'report')
{
    header("Content-type:application/octet-stream");
    header("Accept-Ranges:bytes");
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:attachment;filename=" . $filename . ".xls");
    header("Pragma: no-cache");
    header("Expires: 0");

    $text="<table style='width: 1000px;' border='1'><tr>";
    if (!empty($title)) {
        foreach($title as $k=>$v)
        {
           $text.="<th>".$v."</th>";
        }
        $text.="</tr>";
    }

    if (!empty($data)) {
        foreach ($data as $key => $val){
            $text.="<tr>";
            foreach($val as $k=>$v)
            {
               $text.="<th>".$v."</th>";
            }
            $text.="</tr>";
        }
        echo $text;exit;
    }
}
?>